
var util = require('../../../utils/util.js');
var app = getApp();
Page({
  data: {
  //设置中间的变量在两个函数之间共享
    cartoons:{},
    navigateTitle:"",
    requestUrl:"",
  },
  onLoad: function (options) {
    //页面之间的传递三种方法
    //1.全局变量 //2.缓存 //3.url
  //获取点击的是哪个页面的更多页面
    var category = options.category;
    this.data.navigateTitle = category;
   var dataUrl="";
   switch(category){
     case "少年漫画":
      dataUrl=app.globalData.youyaoqibase + "/youngboy";
      break;
     case "青年漫画":
      dataUrl=app.globalData.youyaoqibase + "/youngman";
   break;
   }
   this.data.requestUrl=dataUrl
   util.http(dataUrl, this.processManhuaData)
  },

  // 下拉加载更多的事件
  onScrollLower:function(event){
      // console.log("加载更多")
      var nextUrl = this.data.requestUrl;
      util.http(nextUrl, this.processManhuaData)
      console.log(nextUrl)

  },
  //列表数据
  processManhuaData:function (manhuaData){
    var result =manhuaData.result;
    // console.log(result)
    var cartoons = [];
    for (var idx in result.bookList) {
      var subject = result.bookList[idx];
      var title = subject.name;
      if (title.length >= 6) {
        title = title.substring(0, 6) + "...";
      }
      var temp = {
        title: title,
        coverImg: subject.coverImg,
        cartoonsid: subject.postid
      }
      cartoons.push(temp)
    }
      this.setData({
        cartoons: cartoons
      })
  },


  //页面渲染完成，设置导航栏标题要设置在onready或者之后的
  onReady:function(event){
    wx.setNavigationBarTitle({
      title: this.data.navigateTitle

    })
  },
  // onCartoonsTap: function (event) {
  //   var cartoonsid = event.currentTarget.dataset.cartoonsid;
  //   wx.navigateTo({
  //     url: 'cartoon-detail/cartoon-detail?id=' + cartoonsid
  //   })
  // }

})